import * as vm from 'vm'
import { log } from 'console'
export default function executeScript(script: string): { success: boolean; output: any } {
  try {
    // 创建一个独立的沙盒环境
    log('execute:', script)
    const context = vm.createContext({})
    const result = new vm.Script(script).runInContext(context)
    log('result', result)
    return { success: true, output: result }
  } catch (error: any) {
    return { success: false, output: error.message }
  }
}
